#include "../inc/LineMesh.h"

void LineMesh::setScaleFromVertexes()
{
     if (numVerts==0)
     {
       scale = 1.0;
       return;
     }
     
     GLfloat minX = vertex[0].x
           , maxX = vertex[0].x
           , minY = vertex[0].y
           , maxY = vertex[0].y
           , minZ = vertex[0].z
           , maxZ = vertex[0].z;
     
     for (int i=1; i<numVerts; i++)
     {
           minX = MIN2(minX, vertex[i].x);
           maxX = MAX2(maxX, vertex[i].x);
           minY = MIN2(minY, vertex[i].y);
           maxY = MAX2(maxY, vertex[i].y);
           minZ = MIN2(minZ, vertex[i].z);
           maxZ = MAX2(maxZ, vertex[i].z);
     }
     
     maxX = MAX2(MAX2(maxX,-maxX),MAX2(minX,-minX));
     maxY = MAX2(MAX2(maxY,-maxY),MAX2(minY,-minY));
     maxZ = MAX2(MAX2(maxZ,-maxZ),MAX2(minZ,-minZ));
     
     scale = MAX3(maxX,maxY,maxZ);
}

void LineMesh::normalizeVertexSpace()
{
     for (int i=0;i<numVerts;i++)
           vertex[i] /= scale;
}

void LineMesh::destroyMesh()
{
   delete[] vertex;
   numVerts = 0;
   scale = 1.0;
}

void LineMesh::render()
{
     glBegin(GL_LINES);
     for (int i=0;i<numVerts;i++)
       (vertex[i] * scale).pushGlVex3f();
     glEnd();
}

